﻿using System.Windows;
using System.Windows.Controls;

namespace Jade.Tools.SL.Controls.LoadingControl
{
    /// <summary>
    /// Loading Control
    /// </summary>
    public partial class Loading : UserControl
    {
        public Loading()
        {
            InitializeComponent();
        }

        #region Dependency Properties

        public bool IsLoading
        {
            get { return (bool)GetValue(IsLoadingProperty); }
            set
            {
                SetValue(IsLoadingProperty, value);
            }
        }

        public static readonly DependencyProperty IsLoadingProperty =
            DependencyProperty.Register("IsLoading", typeof(bool), typeof(Loading), new PropertyMetadata(new PropertyChangedCallback(OnLoadingChanged)));

        private static void OnLoadingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var b = (bool)e.NewValue;
            var l = ((Loading)sender);

            ((Loading)sender).Buffer.IsBusy = b;
            if (b)
            {
                l.Buffer.Visibility = Visibility.Visible;
            }
            else
            {
                l.Buffer.Visibility = Visibility.Collapsed;
            }
        }

        #endregion
    }
}
